package com.wjv.example.service.impl;


import com.wjv.example.common.entity.PaymentEntity;
import com.wjv.example.common.entity.ResultInfo;
import com.wjv.example.dao.PaymentDAO;
import com.wjv.example.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>Title: PaymentServiceImpl</p>
 * <p>Company:misspao </p>
 *
 * @author: wjv
 * @Date: Create in 16:25 2020/9/21
 * @Description:
 */
@Service
public class PaymentServiceImpl implements PaymentService {

    @Autowired
    private PaymentDAO paymentDAO;

    @Override
    public ResultInfo getPayment(int id) {
        PaymentEntity paymentEntity = paymentDAO.queryById(id);
        if (paymentEntity == null) {
            return ResultInfo.error("not fund");
        }

        return ResultInfo.ok("port: 8001", paymentEntity);
    }

    @Override
    public ResultInfo save() {
        PaymentEntity paymentEntity = new PaymentEntity();
        paymentEntity.setOrderNo(UUID.randomUUID().toString());
        int result = paymentDAO.save(paymentEntity);
        if (result <= 0) {
            return ResultInfo.error("操作失败");
        }
        return  ResultInfo.ok(paymentEntity);
    }
}
